﻿using AmuTools;
using app.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace app.Models
{
    [Model(TableName = "t_plateform_abutment", PrimaryKey = "id", IdentityInsert = true)]
    public class PlateformServiceAbutment
    {
        [Field(Description ="平台服务对接信息的唯一标识")]
        public int id { get; set; }

        [Field(Description ="申请平台服务的企业标识")]
        public int company_id { get; set; }

        [Field(DataType = "nvarchar(MAX)",Description ="平台服务对接信息的唯一编号：'a'+平台服务编号+企业ID")]
        public string number { get; set; }

        [Field(Description = "对应平台服务的编号，用来在审核页面进行分类查询")]
        public string service_number { get; set; }   

        [Field(Storageable = false,Description ="申请该平台服务的会员ID")]
        public int service_member_id { get { return company_id; } }

        [Field(Storageable = false,Description ="处理该条信息的管理员ID")]
        public int demand_member_id { get { return admin_id; } }
        
        private Member _member = null;

        [Field(Storageable = false, IsPrivate = true,Description ="申请该项平台服务的会员信息")]
        public Member member
        {
            get
            {
                if (_member == null)
                {
                    _member = G.DB.GetById<Member>(company_id);
                }
                return _member;
            }
        }

        [Field(Description ="管理员ID")]
        public int admin_id { get; set; }//管理员id

        private Admin _admin = null;

        [Field(Storageable = false,Description ="处理该条服务的管理员信息")]
        public Admin admin
        {
            get
            {
                if (_admin == null)
                {
                    _admin = G.DB.GetById<Admin>(admin_id);
                }
                return _admin;
            }
        }

        [Field(Description ="对接创建时间")]
        public string create_time { get; set; }

        [Field(Description ="对应的平台服务的ID")]
        public int plateformservice_id { get; set; }

        [Field(Description = "对应的平台服务的名称")]
        public string title { get; set; }

        [Field(Storageable = false,Description ="该项平台服务对应的ID")]
        public int service_id { get { return plateformservice_id; } }//

        private PlateformService _plateformservice = null;

        [Field(Storageable = false,Description ="平台服务对应的详细信息")]
        public PlateformService plateformservice
        {
            get
            {
                if (_plateformservice == null)
                {
                    _plateformservice = G.DB.GetById<PlateformService>(plateformservice_id);
                }
                return _plateformservice;
            }
        }

        public string process { get; set; }//流程, 已经不要了，千万不要用这个属性了

        [Field(Storageable = false,Description ="流程信息")]
        public List<Step> steps
        {
            get
            {
                return Step.GetSteps(service_id);
            }
        }

        [Field(Storageable = false,Description = "当前步骤序号")]
        public StepAbutmentData step_abutment_data
        { // 当前步骤序号
            get
            {
                return G.DB.GetById<StepAbutmentData>(id);
            }
        }

        private string _appendix_ids = "";//附件

        private List<UploadedFile> _appendix = null;

        [Field(Description = "逗号分隔的附件ID数组")]
        public string appendix_ids
        {
            get { return _appendix_ids; }
            set
            {
                _appendix_ids = value;
                _appendix = null;
            }
        }

        [Field(Storageable = false,Description ="附件数组")]
        public List<UploadedFile> appendix
        {
            get
            {
                if (_appendix == null)
                {
                    if (appendix_ids == "") _appendix = new List<UploadedFile>();
                    else _appendix = G.DB.Get<UploadedFile>(string.Format("{0} in ({1})", G.DB.GetPrimaryKey<UploadedFile>(), appendix_ids)).GetFirstTableList<UploadedFile>();
                }
                return _appendix;
            }
        }

        [Field(Description ="状态：0删除，1审核，2通过，申领成功，3不通过，申领失败")]
        public int status { get; set; }

        static public Dictionary<string, string> ExcelColumns
        {
            get
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("number", "编号");
                dic.Add("title", "需求名称");
                dic.Add("create_time", "添加时间");
                dic.Add("status", "状态");
                return dic;
            }
        }

        static public Dictionary<string, Func<object, object>> ExcelColumnsHandle
        {
            get
            {
                Dictionary<string, Func<object, object>> dic = new Dictionary<string, Func<object, object>>();
                dic.Add("create_time", value => {
                    return DateTimeEx.TimeStampToDatetime(value.ToString());
                });
                return dic;
            }
        }
    }
}